home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p4fillp.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  120 lines

  1. /** 
  2.  ** P4FILLP.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p4.h"
  25. #include "memfill.h"
  26. #include "memcopy.h"
  27.  
  28. void _GrP4FillPattern(int x,int y,int width,GrPattern *p)
  29. {
  30.     if(width <= 0) return;
  31.     x += CURC->gc_xoffset;
  32.     y += CURC->gc_yoffset;
  33.     if(p->gp_ispixmap) {
  34.         GrContext *dst = (CURC->gc_root == NULL) ? CURC : CURC->gc_root;
  35.         GrContext *src = (GrContext *)(&p->gp_pxp_source);
  36.         int  pattwdt = p->gp_pxp_width;
  37.         int  optype  = p->gp_pxp_oper;
  38.         int  cpysize = x % pattwdt;
  39.         long dstaddr = PIX_ADDR(dst,x,y);
  40.         long srcline = PIX_ADDR(src,0,(y % p->gp_pxp_height));
  41.         long srcaddr = srcline + cpysize;
  42.  
  43.         cpysize = pattwdt - cpysize;
  44.         while(width > 0) {
  45.         if(cpysize > width) cpysize = width;
  46.         _GrP4PixCopy(dst,dstaddr,src,srcaddr,cpysize,1,optype);
  47.         width    -= cpysize;
  48.         dstaddr += cpysize;
  49.         srcaddr  = srcline;
  50.         cpysize  = pattwdt;
  51.         }
  52.     }
  53.     else {
  54.         pixptr ptr = (pixptr)
  55.         (CURC->gc_baseaddr + (y * CURC->gc_lineoffset) + (x >> 3));
  56.         int bits = p->gp_bmp_data[y % p->gp_bmp_height];
  57.         int fgc  = p->gp_bmp_fgcolor;
  58.         int bgc  = p->gp_bmp_bgcolor;
  59.         int fgop = C_OPER(fgc);
  60.         int bgop = C_OPER(bgc);
  61.         int dofg = _GrP4DrawTable[fgop] ^ (fgc &= C_SIGNIF);
  62.         int dobg = _GrP4DrawTable[bgop] ^ (bgc &= C_SIGNIF);
  63.         int plane,lmask,rmask;
  64.  
  65.         _ClrDir();
  66.         _ComputeMasks(x,width,lmask,rmask);
  67.         for(x = 2; --x >= 0; fgc = bgc,fgop = bgop,dofg = dobg,bits = ~bits) {
  68.         pixptr p = ptr;
  69.         if(!dofg) continue;
  70.         if(CURC->gc_onscreen) {
  71.             _SetVideoColor(fgc,fgop);
  72.             if(lmask) { _SetVGAWriteMask(lmask & bits); (*p)++; p++; }
  73.             if(width) {
  74.             _SetVGAWriteMask(bits);
  75.             _SaveDS();
  76.             _RowCpyB(VRAM,p,p,width);
  77.             _RestoreDS();
  78.             p += width;
  79.             }
  80.             if(rmask) { _SetVGAWriteMask(rmask & bits); (*p)++; }
  81.             continue;
  82.         }
  83.         fgop <<= 1;
  84.         for(plane = 4; --plane >= 0; fgc >>= 1) {
  85.             pixptr pp = p;
  86.             switch(fgop | (fgc & 1)) {
  87.               case C_XOR2+1:
  88.             if(lmask) *pp++ ^= (lmask & bits);
  89.             if(width) {
  90.                 _RowSetXorB(MEM_X,pp,bits,width);
  91.                 pp += width;
  92.             }
  93.             if(rmask) *pp ^= (rmask & bits);
  94.             break;
  95.               case C_OR2+1:
  96.               case C_SET2+1:
  97.             if(lmask) *pp++ |= (lmask & bits);
  98.             if(width) {
  99.                 _RowSetOrB(MEM_1,pp,bits,width);
  100.                 pp += width;
  101.             }
  102.             if(rmask) *pp |= (rmask & bits);
  103.             break;
  104.               case C_AND2+0:
  105.               case C_SET2+0:
  106.             if(lmask) *pp++ &= ~(lmask & bits);
  107.             if(width) {
  108.                 _RowSetAndB(MEM_0,pp,~bits,width);
  109.                 pp += width;
  110.             }
  111.             if(rmask) *pp &= ~(rmask & bits);
  112.             break;
  113.             }
  114.             p = (pixptr)((long)p + CURC->gc_planeoffset);
  115.         }
  116.         }
  117.     }
  118. }
  119.  
  120.